﻿@{
    ViewBag.Title = "FoodAdd";
    Layout = "~/Views/Shared/_Layout.cshtml";
    var Dic = FoodType_Bll.GetFoodTypeDictionary();
}

<div class="main-container">
    <div class="modal-form">
        <div class="modal-form-body">
            <form id="Form" method="post" class="form-horizontal margin10-t">
                <div class="contrl">
                    <label>分类：</label>
                    <select class="select" id="TypeID" name="TypeID">
                        @foreach (KeyValuePair<int, string> kvp in Dic)
                        {
                            <option value="@kvp.Key">@kvp.Value</option>
                        }
                    </select>
                </div>
                <div class="contrl">
                    <label>菜名：</label>
                    <input type="text" name="FoodName" class="input">
                </div>
                <div class="contrl">
                    <label>单价：</label>
                    <input type="text" name="Price" class="input">
                </div>
                <div class="contrl">
                    <label>折扣：</label>
                    <input type="text" name="Discount" class="input" value="1">
                </div>
            </form>
        </div>
        <div class="modal-form-footer">
            <input type="button" class="btn-primary" value="保存" onclick="autoSubmit('System', 'FoodAdd', 'FoodList')" />
            <input type="button" class="btn-secondary" value="取消" onclick="CloseModelFrame()">
        </div>
    </div>
</div>
<script type="text/javascript">
    //验证字段
    $(document).ready(function () {
        $("#Form").validate({
            rules: {
                FoodName: { required: true, maxlength: 50 },
                Price: { required: true, number: true, min: 0.01 },
                Discount: { required: true, number: true, range: [0.001, 1] }
            },
            messages: {
                FoodName: {
                    required: "请输入菜名",
                    maxlength: "菜名长度最多50字"
                },
                Price: {
                    required: "请输入单价",
                    number: "必须为数字",
                    min: "单价必须大于0"
                },
                Discount: {
                    required: "请输入折扣",
                    number: "必须为数字",
                    range: "折扣必须在0-1之间的数字，如5折则填写0.5",
                }
            },
            errorElement: "em"
        });
    });
</script>
